package com.heavenick.app.jmx;

import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.ObjectInstance;
import javax.management.ObjectName;

import com.sun.jdmk.comm.HtmlAdaptorServer;

/**
 * 
 * @author HaiJun
 * @date 2013-2-4
 */
public class HelloAgent implements NotificationListener {
	public static void main(String[] args) throws Exception {        
		MBeanServer server = MBeanServerFactory.createMBeanServer("test1");
		ObjectName helloName = new ObjectName("chengang:name=HelloWorld");        
		Hello hello=new Hello();
		//server.registerMBean(new TestHelloMBean(), helloName);
//		hello.addNotificationListener(new HelloAgent(), null, null);
		ObjectName adapterName = new ObjectName("HelloAgent:name=htmladapter,port=8082");        
		HtmlAdaptorServer adapter = new HtmlAdaptorServer();
		adapter.
		server.registerMBean(adapter, adapterName);
		adapter.start();        
		System.out.println("start.....");    
		ech
		
//		ObjectInstance object = server.getObjectInstance(helloName);
//		System.out.println(object.getClassName());
//		System.out.println(object.toString());;
//		System.out.println();
//		
//		for(;;){
//			Hello obj = (Hello)server.instantiate(object.getClassName());
//			System.out.println(obj.getName()+" test new Hello for MBean server " + server.getAttribute(helloName, "Name"));
//			try {
//				Thread.sleep(3000L);
//			} catch (Exception e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//			
//		}
	}

	public void handleNotification(Notification notification, Object handback) {
		System.out.println( "Receiving notification ..." );
       System.out.println( notification.getType() );
       System.out.println( notification.getMessage() );
		
	}

}
